import 'package:flutter/material.dart';

/// 圆角容器。圆角半径默认为 8，背景色默认为白色。
class RoundedContainer extends StatelessWidget {
  /// 圆角容器。圆角半径默认为 8，背景色默认为白色。
  const RoundedContainer({
    super.key,
    this.padding,
    this.margin,
    this.width,
    this.height,
    this.constraints,
    this.color = Colors.white,
    this.gradient,
    this.radius = 8,
    this.borderRadius,
    this.borderWidth,
    this.borderColor,
    this.alignment,
    this.matrix4,
    this.child,
    this.boxShadowList
  });

  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final double? width;
  final double? height;
  final BoxConstraints? constraints;
  final Color? color;
  final Gradient? gradient;
  final Widget? child;
  final double radius;
  final BorderRadius? borderRadius;
  final double? borderWidth;
  final Color? borderColor;
  final Alignment? alignment;
  final Matrix4? matrix4;
  final List<BoxShadow>? boxShadowList;

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: alignment,
      padding: padding,
      margin: margin,
      width: width,
      height: height,
      constraints: constraints,
      transform: matrix4,
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(
          border: border,
          borderRadius: borderRadius ?? BorderRadius.circular(radius),
          color: gradient == null ? color : null,
          gradient: gradient,
          boxShadow: boxShadowList),
      child: child,
    );
  }

  Border? get border {
    final w = borderWidth;
    if (w == null || w <= 0) return null;
    return Border.all(
      color: borderColor ?? Colors.white,
      width: w,
    );
  }
}
